from django.db import models

# Create your models here.
from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
from utils.models import BaseModel
from utils.qiniu_storage import QiNiuStorage


class User(AbstractUser):
    """自定义用户模型类"""
    username=models.CharField(unique=True,max_length=20,verbose_name='用户名')
    mobile = models.CharField(max_length=11,  verbose_name='手机号')
    nickname=models.CharField(max_length=20,verbose_name='昵称')
    email = models.CharField(max_length=40,verbose_name='邮箱')
    user_pic = models.CharField(max_length=200,verbose_name='头像')
    # user_pic = models.CharField(storage=QiNiuStorage,verbose_name='头像')
    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return self.username

# def upload_to(instance,filename):
#     return  'wenjianjia text'

class UserImage(BaseModel):
    """自定义用户模型类"""
    user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户')
    # cover_img = models.ImageField(storage=QiNiuStorage(),verbose_name='头像',upload_to=upload_to)
    cover_img = models.ImageField(storage=QiNiuStorage(), verbose_name='头像')
    class Meta:
        db_table = 'tb_user_img'
        verbose_name = '用户头像'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return '%s %s' % (self.user.name, self.id)